package com.yww.datastructure.deque;

/**
 * @author yww
 * @description 双端队列
 * @since 2024/2/5 14:29
 */
public interface Deque<E> extends Iterable<E> {
    boolean offerFirst(E e);

    boolean offerLast(E e);

    E pollFirst();

    E pollLast();

    E peekFirst();

    E peekLast();

    boolean isEmpty();

    boolean isFull();

    default String asString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        for (E e : this) {
            stringBuilder.append(e);
            stringBuilder.append(", ");
        }

        if (!isEmpty()) {
            stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(" "));
            stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
        }
        stringBuilder.append("]");
        return stringBuilder.toString();
    }
}
